<!--$Id: intro.so,v 10.26 2007/04/05 20:54:56 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Introduction to the memory pool subsystem</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a><a name="3"><!--meow--></a><a name="4"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Memory Pool Subsystem</dl></b></td>
<td align=right><a href="../log/limits.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../mp/config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Introduction to the memory pool subsystem</b></p>
<p>The Memory Pool subsystem is the general-purpose shared memory buffer
pool used by Berkeley DB.  This module is useful outside of the Berkeley DB package
for processes that require page-oriented, shared and cached file access.</p>
<p>A <i>memory pool</i> is a memory cache shared among any number of
threads of control.  The <a href="../../api_c/env_open.html#DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag to the
<a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> method opens and optionally creates a memory pool.  When
that pool is no longer in use, it should be closed using the
<a href="../../api_c/env_close.html">DB_ENV-&gt;close</a> method.</p>
<p>The <a href="../../api_c/memp_fcreate.html">DB_ENV-&gt;memp_fcreate</a> method returns a <a href="../../api_c/mempfile_class.html">DB_MPOOLFILE</a> handle on an
underlying file within the memory pool.  The file may be opened using
the <a href="../../api_c/memp_fopen.html">DB_MPOOLFILE-&gt;open</a> method.  The <a href="../../api_c/memp_fget.html">DB_MPOOLFILE-&gt;get</a> method is used to retrieve
pages from files in the pool.  All retrieved pages must be subsequently
returned using the <a href="../../api_c/memp_fput.html">DB_MPOOLFILE-&gt;put</a> method.  At the time pages are returned,
they may be marked <b>dirty</b>, which causes them to be written to
the underlying file before being discarded from the pool.  If there is
insufficient room to bring a new page in the pool, a page is selected
to be discarded from the pool using a least-recently-used algorithm.
All dirty pages in the pool from the file may be flushed using the
<a href="../../api_c/memp_fsync.html">DB_MPOOLFILE-&gt;sync</a> method.  When the file handle is no longer in use, it
should be closed using the <a href="../../api_c/memp_fclose.html">DB_MPOOLFILE-&gt;close</a> method.</p>
<p>There are additional configuration interfaces that apply when opening
a new file in the memory pool:</p>
<p><ul type=disc>
<li>The <a href="../../api_c/memp_set_clear_len.html">DB_MPOOLFILE-&gt;set_clear_len</a> method specifies the number of bytes to clear
when creating a new page in the memory pool.
<li>The <a href="../../api_c/memp_set_fileid.html">DB_MPOOLFILE-&gt;set_fileid</a> method specifies a unique ID associated with the file.
<li>The <a href="../../api_c/memp_set_ftype.html">DB_MPOOLFILE-&gt;set_ftype</a> method specifies the type of file for the purposes of
page input and output processing.
<li>The <a href="../../api_c/memp_set_lsn_offset.html">DB_MPOOLFILE-&gt;set_lsn_offset</a> method specifies the byte offset of each page's
log sequence number (<a href="../../api_c/lsn_class.html">DB_LSN</a>) for the purposes of transaction
checkpoints.
<li>The <a href="../../api_c/memp_set_pgcookie.html">DB_MPOOLFILE-&gt;set_pgcookie</a> method specifies an application provided argument
for the purposes of page input and output processing.
</ul>
<p>There are additional interfaces for the memory pool as a whole:</p>
<p><ul type=disc>
<li>It is possible to gradually flush buffers from the pool in order to
maintain a consistent percentage of clean buffers in the pool using
the <a href="../../api_c/memp_trickle.html">DB_ENV-&gt;memp_trickle</a> method.
<li>Because special-purpose processing may be necessary when pages are read
or written (for example, endian conversion, or page checksums), the
<a href="../../api_c/memp_register.html">DB_ENV-&gt;memp_register</a> function allows applications to specify automatic
input and output processing in these cases.
<li>The <a href="../../utility/db_stat.html">db_stat</a> utility uses the <a href="../../api_c/memp_stat.html">DB_ENV-&gt;memp_stat</a> method to display
statistics about the efficiency of the pool.
<li>All dirty pages in the pool may be flushed using the <a href="../../api_c/memp_sync.html">DB_ENV-&gt;memp_sync</a> method.
In addition, <a href="../../api_c/memp_sync.html">DB_ENV-&gt;memp_sync</a> takes an argument that is specific to
database systems, and which allows the memory pool to be flushed up to
a specified log sequence number (<a href="../../api_c/lsn_class.html">DB_LSN</a>).
<li>The entire pool may be discarded using the <a href="../../api_c/env_remove.html">DB_ENV-&gt;remove</a> method.
</ul>
<!--$Id: m4.methods,v 1.11 2007/07/06 00:22:53 mjc Exp $-->
<table border=1 align=center>
<tr><th>Memory Pools and Related Methods</th><th>Description</th></tr>
<!--Db::mpf--><tr><td><a href="../../api_c/db_get_mpf.html">DB-&gt;get_mpf</a></td><td>Return <a href="../../api_c/db_class.html">DB</a>'s underlying <a href="../../api_c/mempfile_class.html">DB_MPOOLFILE</a> handle</td></tr>
<!--DbEnv::memp_stat--><tr><td><a href="../../api_c/memp_stat.html">DB_ENV-&gt;memp_stat</a></td><td>Return memory pool statistics</td></tr>
<!--DbEnv::memp_sync--><tr><td><a href="../../api_c/memp_sync.html">DB_ENV-&gt;memp_sync</a></td><td>Flush pages from a memory pool</td></tr>
<!--DbEnv::memp_trickle--><tr><td><a href="../../api_c/memp_trickle.html">DB_ENV-&gt;memp_trickle</a></td><td>Trickle flush pages from a memory pool</td></tr>
<!--DbMemoryException-->
<tr><th>Memory Pool Configuration</th><th><br></th></tr>
<!--DbEnv::memp_register--><tr><td><a href="../../api_c/memp_register.html">DB_ENV-&gt;memp_register</a></td><td>Register input/output functions for a file in a memory pool</td></tr>
<!--DbEnv::set_cachesize--><tr><td><a href="../../api_c/env_set_cachesize.html">DB_ENV-&gt;set_cachesize</a></td><td>Set the environment cache size</td></tr>
<!--DbEnv::set_cache_max--><tr><td><a href="../../api_c/env_set_cache_max.html">DB_ENV-&gt;set_cache_max</a></td><td>Set the maximum cache size</td></tr>
<!--DbEnv::set_mp_max_openfd--><tr><td><a href="../../api_c/memp_openfd.html">DB_ENV-&gt;set_mp_max_openfd</a></td><td>Set the maximum number of open file descriptors</td></tr>
<!--DbEnv::set_mp_max_write--><tr><td><a href="../../api_c/memp_maxwrite.html">DB_ENV-&gt;set_mp_max_write</a></td><td>Set the maximum number of sequential disk writes</td></tr>
<!--DbEnv::set_mp_mmapsize--><tr><td><a href="../../api_c/env_set_mp_mmapsize.html">DB_ENV-&gt;set_mp_mmapsize</a></td><td>Set maximum mapped-in database file size</td></tr>
<tr><th>Memory Pool Files</th><th><br></th></tr>
<!--DbEnv::memp_fcreate--><tr><td><a href="../../api_c/memp_fcreate.html">DB_ENV-&gt;memp_fcreate</a></td><td>Create a memory pool file handle</td></tr>
<!--DbMpoolFile::-->
<!--DbMpoolFile::close--><tr><td><a href="../../api_c/memp_fclose.html">DB_MPOOLFILE-&gt;close</a></td><td>Close a file in a memory pool</td></tr>
<!--DbMpoolFile::get--><tr><td><a href="../../api_c/memp_fget.html">DB_MPOOLFILE-&gt;get</a></td><td>Get page from a file in a memory pool</td></tr>
<!--DbMpoolFile::open--><tr><td><a href="../../api_c/memp_fopen.html">DB_MPOOLFILE-&gt;open</a></td><td>Open a file in a memory pool</td></tr>
<!--DbMpoolFile::put--><tr><td><a href="../../api_c/memp_fput.html">DB_MPOOLFILE-&gt;put</a></td><td>Return a page to a memory pool</td></tr>
<!--DbMpoolFile::sync--><tr><td><a href="../../api_c/memp_fsync.html">DB_MPOOLFILE-&gt;sync</a></td><td>Flush pages from a file in a memory pool</td></tr>
<tr><th>Memory Pool File Configuration</th><th><br></th></tr>
<!--DbMpoolFile::set_clear_len--><tr><td><a href="../../api_c/memp_set_clear_len.html">DB_MPOOLFILE-&gt;set_clear_len</a></td><td>Set file page bytes to be cleared</td></tr>
<!--DbMpoolFile::set_fileid--><tr><td><a href="../../api_c/memp_set_fileid.html">DB_MPOOLFILE-&gt;set_fileid</a></td><td>Set file unique identifier</td></tr>
<!--DbMpoolFile::set_flags--><tr><td><a href="../../api_c/memp_set_flags.html">DB_MPOOLFILE-&gt;set_flags</a></td><td>General memory pool file configuration</td></tr>
<!--DbMpoolFile::set_ftype--><tr><td><a href="../../api_c/memp_set_ftype.html">DB_MPOOLFILE-&gt;set_ftype</a></td><td>Set file type</td></tr>
<!--DbMpoolFile::set_lsn_offset--><tr><td><a href="../../api_c/memp_set_lsn_offset.html">DB_MPOOLFILE-&gt;set_lsn_offset</a></td><td>Set file log-sequence-number offset</td></tr>
<!--DbMpoolFile::set_maxsize--><tr><td><a href="../../api_c/memp_set_maxsize.html">DB_MPOOLFILE-&gt;set_maxsize</a></td><td>Set maximum file size</td></tr>
<!--DbMpoolFile::set_pgcookie--><tr><td><a href="../../api_c/memp_set_pgcookie.html">DB_MPOOLFILE-&gt;set_pgcookie</a></td><td>Set file cookie for pgin/pgout</td></tr>
<!--DbMpoolFile::set_priority--><tr><td><a href="../../api_c/memp_set_priority.html">DB_MPOOLFILE-&gt;set_priority</a></td><td>Set memory pool file priority</td></tr>
</table>
<table width="100%"><tr><td><br></td><td align=right><a href="../log/limits.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../mp/config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
